package model;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/30.
 */
public class MineModel {
    /**
     * result : 1
     * data : []
     * links : [{"tag":"like","name":"我的喜欢","icon":"http://static.shandjj.com/app/images/user_center/my_like.png","url":""},{"tag":"address","name":"收货地址","icon":"http://static.shandjj.com/app/images/user_center/my_address.png","url":""},{"tag":"bask","name":"我的晒单","icon":"http://static.shandjj.com/app/images/user_center/my_order.png","url":""},{"tag":"wap","name":"我的财富","icon":"http://static.shandjj.com/app/images/user_center/my_money.png","url":"http://m.shandjj.com/stock/showMyStockInfo"},{"tag":"wap","name":"优惠券","icon":"http://static.shandjj.com/app/images/user_center/my_coupon.png","url":"http://m.shandjj.com/user/showUserCoupon"},{"tag":"history","name":"浏览记录","icon":"http://static.shandjj.com/app/images/user_center/my_footprint.png","url":""}]
     */

    private int result;
    private List<?> data;
    /**
     * tag : like
     * name : 我的喜欢
     * icon : http://static.shandjj.com/app/images/user_center/my_like.png
     * url :
     */

    private List<LinksBean> links;

    public static MineModel objectFromData(String str) {

        return new Gson().fromJson(str, MineModel.class);
    }

    public static MineModel objectFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);

            return new Gson().fromJson(jsonObject.getString(str), MineModel.class);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static List<MineModel> arrayMineModelFromData(String str) {

        Type listType = new TypeToken<ArrayList<MineModel>>() {
        }.getType();

        return new Gson().fromJson(str, listType);
    }

    public static List<MineModel> arrayMineModelFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);
            Type listType = new TypeToken<ArrayList<MineModel>>() {
            }.getType();

            return new Gson().fromJson(jsonObject.getString(str), listType);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return new ArrayList();


    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public List<?> getData() {
        return data;
    }

    public void setData(List<?> data) {
        this.data = data;
    }

    public List<LinksBean> getLinks() {
        return links;
    }

    public void setLinks(List<LinksBean> links) {
        this.links = links;
    }

    public static class LinksBean {
        private String tag;
        private String name;
        private String icon;
        private String url;

        public static LinksBean objectFromData(String str) {

            return new Gson().fromJson(str, LinksBean.class);
        }

        public static LinksBean objectFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);

                return new Gson().fromJson(jsonObject.getString(str), LinksBean.class);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        public static List<LinksBean> arrayLinksBeanFromData(String str) {

            Type listType = new TypeToken<ArrayList<LinksBean>>() {
            }.getType();

            return new Gson().fromJson(str, listType);
        }

        public static List<LinksBean> arrayLinksBeanFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);
                Type listType = new TypeToken<ArrayList<LinksBean>>() {
                }.getType();

                return new Gson().fromJson(jsonObject.getString(str), listType);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return new ArrayList();


        }

        public String getTag() {
            return tag;
        }

        public void setTag(String tag) {
            this.tag = tag;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getIcon() {
            return icon;
        }

        public void setIcon(String icon) {
            this.icon = icon;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }
    }
}
